package tech.aistar.day01;

import java.util.Arrays;


/**
 * 本类用来演示: 方法参数的传递方式
 *
 * @author: success
 * @date: 2022/7/18 4:02 下午
 */
public class ParamTransferDemo {
    public static void main(String[] args) {
        //基本类型 - 值传递,将变量中保存的值拷贝一份给副本[方法形参]
        //但是java.lang.String虽然是对象类型,但是具备值传递的特性.
        //文件的拷贝
        int a = 10;
        int b = 20;

        change(a,b);//实参,实际的值

        System.out.println("main-a:"+a);//10
        System.out.println("main-b:"+b);//20

        //对象类型 - 引用传递/地址传递

        //  栈                 堆
        //  main-arr1        {11,12,13}

        //   add-arr1
        int[] arr1 = new int[]{1,2,3};

        System.out.println(arr1);//对象的内存地址

        add(arr1);

        System.out.println("main:"+ Arrays.toString(arr1));//[11, 12, 13]
    }

    private static void add(int[] arr1) {
        for (int i = 0; i < arr1.length; i++) {
            arr1[i]  = arr1[i]+10;
        }
        System.out.println("add:"+ Arrays.toString(arr1));//[11, 12, 13]
    }

    private static void change(int a, int b) {//形参 - 无实际值
        a = a^b;
        b = a^b;
        a = a^b;

        System.out.println("change-a:"+a);//20
        System.out.println("change-b:"+b);//10
    }


}
